<template>
  <t-dialog :header="`${header}【当前已勾选${selectedRowKeys.length}】【待评审标准数${projectList.length}】`" @confirm="onSubmit" :confirmBtn="{
        content: loading?'提交中...':'确认',
        theme: 'primary',
        loading: loading,
      }" :visible.sync="visible" :onClose="closeDialog"     :closeOnOverlayClick="false"
            width="80%" top="5%">
    <div style="height: 65vh">
      <div style="display: flex;font-weight: bold;justify-content: center;font-size: 30px;padding: 30px">
        标准列表
      </div>
    <t-table row-key="id" :columns="columns" :data="data" :selected-row-keys="selectedRowKeys"
              :loading="dataLoading"
             @select-change="(val)=>{selectedRowKeys=val}">
      <template #projectName="{ row }">
        <t-link @click="nameClick(row)" hover="color" theme="primary">{{ row.projectName }}</t-link>
      </template>
      <template #standardProperty="{ row }">
        {{ row.standardProperty | filterByDict(dict.type.standard_property) }}
      </template>
      <template #systemName="{ row }">
        {{row.systemName || "-"}}
      </template>
      <template #formulateType="{ row }">
        {{ row.formulateType | filterByDict(dict.type.formulate_type) }}
      </template>
      <template #standardCategory="{ row }">
        {{ row.standardCategory | filterByDict(dict.type.standard_category) }}
      </template>
      <template #reviseNum="{ row }">
        {{ row.reviseNum || "-" }}
      </template>
      <template #draftUnitNames="{ row }">
        <t-tooltip :content="row.draftUnitNames">
          <p style="display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; text-overflow: ellipsis; overflow: hidden;">
            {{row.draftUnitNames || "-"}}
          </p>
        </t-tooltip>
      </template>
      <template #consistencyDegree="{ row }">
        {{row.consistencyDegree || "-"}}
      </template>
      <template #internationalStandardNum="{ row }">
        {{row.internationalStandardNum || "-"}}
      </template>
<!--      <template #manageDeptId="{ row }">-->
<!--        {{ row.manageDeptId | filterByTree(deptMenuOptions) }}-->
<!--      </template>-->
      <template #completeDate="{ row }">
        {{row.completeDate|| "-"}}
      </template>
      <template #publishDate="{ row }">
        {{row.publishDate|| "-"}}
      </template>
      <template #implDate="{ row }">
        {{row.implDate|| "-"}}
      </template>
      <template #localStandardStatus="{ row }">
        <t-tag  @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.localStandardStatus, dict.type.local_standard_status)" variant="light">
          {{ row.localStandardStatus | filterByDict(dict.type.local_standard_status) }}
        </t-tag>
      </template>
      <template #op="{row}">
        <t-button @click="dialog.header=row.name;dialog.objId=row.id;dialog.editOpen=false;dialog.open_detail=true" size="small" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
      </template>
    </t-table>
      <standardDetailDialog  :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
      </standardDetailDialog>
    </div>
  </t-dialog>
</template>

<script>
import standardDetailDialog from "@/pages/bzh/standard/components/standard-detail-dialog.vue";

export default {
  name: "select-project",
  dicts: ["local_standard_status", "standard_category", "standard_property", "formulate_type"],
  components:{
    standardDetailDialog
  },
  props: {
    header:{
      type:String,
      default:''
    },
    formData: {
      type: Object,
      default: () => ({})
    },
    projectList: {
      type: Array,
      default: ()=>[]
    }
  },
  data() {
    return {
      dialog:{
        header:"",
        objId:0,
        open_detail: false,
        editOpen: true,
      },
      selectedRowKeys: [],
      queryParams: {
        reviewType: '',
        pageNum: 1,
        pageSize: 10,
        dateRange: []
      },
      data:[],
      dataLoading: false,
      pagination: {
        defaultCurrent: 1,
        defaultPageSize: 10,
        total: 0,
        showPageSize: false,
        showFirstAndLastPageBtn: false,
      },
      columns: [
        {
          colKey: 'row-select',
          type: 'multiple',
          className: 'demo-multiple-select-cell',
          width: 64,
        },
        // {
        //   colKey: "projectNum",
        //   title: "标准编号",
        //   align: "center",
        //   width: 160,
        // },
        {
          colKey: "projectName",
          title: "标准名称",
          align: "center",
          width: 220
        },
        {
          colKey: "systemName",
          title: "标准体系",
          align: "center",
          width: 160,
        },
        {
          colKey: "standardProperty",
          title: "标准性质",
          align: "center",
          width: 160,
        },
        {
          colKey: "standardCategory",
          title: "标准类别",
          align: "center",
          width: 160,
        },
        {
          colKey: "formulateType",
          title: "制定或修订",
          align: "center",
          width: 160,
        },
        {
          colKey: "draftUnitNames",
          title: "主要起草单位",
          align: "center",
          width: 160,
          ellipsis: true,
        },
        {
          colKey: "completeDate",
          title: "完成时间",
          align: "center",
          width: 160,
          // sorter: true,
        },
        // {
        //   colKey: "publishDate",
        //   title: "发布时间",
        //   align: "center",
        //   width: 160,
        //   // sorter: true,
        // },
        // {
        //   colKey: "implDate",
        //   title: "实施时间",
        //   align: "center",
        //   width: 160,
        //   // sorter: true,
        // },
        // {
        //   colKey: "localStandardStatus",
        //   title: "标准状态",
        //   align: "center",
        //   width: 160,
        // },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120
        },
      ],
      visible: true,
      loading: false,
    }
  },
  watch: {
    formData: {
      immediate: true,
      handler(val) {
        if(val.id){
          this.getList();
        }
      }
    }
  },
  methods: {
    getList() {
      this.dataLoading = true;
      // this.queryParams.pageNum = this.pagination.current || 1;
      this.queryParams.reviewType = this.formData.reviewType;
      this.queryParams.teamId = this.formData.id;
      this.$api.bzh.review.teamProjectListByReviewType(this.queryParams).then((res) => {
        this.data = res.data;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading=false
        this.$message.error(e.toString());
      });
    },
    onSubmit(){
      if (this.selectedRowKeys.length === 0) {
        this.$message.error('请选择项目')
        return false
      }
      const businessId = this.selectedRowKeys.map(val=>({
        teamId:this.formData.id,
        businessId:val,
        reviewType: this.formData.reviewType
      }))
      this.loading = true;
      this.$api.bzh.review.teamProjectAddList(businessId).then((res) => {
        // 初始化
        this.$message.success("选择成功");
        this.$emit("reload");
        this.$emit("update:visible", false);
        this.loading = false;
      }).catch((e) => {
        this.loading = false;
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },

  }
}
</script>

<style scoped>
.overlay-options {
  display: inline-block;
  font-size: 20px;
}
</style>
